import axios from 'axios'
import cookie from 'js-cookie'
// 导入 NProgress 包对应的JS和CSS
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
const service = axios.create({
  baseURL: 'http://localhost:4141/his',
  timeout: 5000 // request timeout
})

// request请求拦截
service.interceptors.request.use(config => {
  // console.log(config)
  NProgress.start()
  if (cookie.get('his_token')) {
    config.headers['token'] = cookie.get('his_token');
  }
  // 在最后必须 return config
  return config
})
// 在 response 拦截器中，隐藏进度条 NProgress.done()
service.interceptors.response.use(config => {
  NProgress.done()
  return config
})

export default service
